const Koa = require('koa')
const Router = require('koa-router')
const serve = require('koa-static');
const path = require('path')
const Pug = require('koa-pug')
// const pug = require('pug')
const app = new Koa()
const routes = require('./routes')

// const render = (ctx, next) => {
//     if (ctx.render) return next()
//     ctx.response.render = ctx.render = async (page, locals = {}) => {
//         const state = Object.assign(locals, ctx.state || {})
//         ctx.type = 'text/html'
//         ctx.body = pug.renderFile(`./pages/${page}/${page}.pug`, state);
//     }
//     return next()
// }

// app.use(render)
const pug = new Pug({
    viewPath: './pages',
    app: app
});

app.use(serve('.'))

routes(app)

app.on('error', err => {
    console.error('server error', err)
});

app.listen(9003);
